package com.gxuwz.xmlrw;

import java.io.FileWriter;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

public class DomWrite {
	 public static void main(String args[])throws Exception{  
	        //创建一个文档对象  
	        Document document  = DocumentHelper.createDocument();  
	  
	  
	        //构造dom树  
	        Element roote = document.addElement("academys");  
	        Element child = roote.addElement("academy"); 
	        child.addElement("id").addText("1");  
	        child.addElement("academyName").addText("北京院校");
	          
	        //设置字符编码方式  
	        OutputFormat format = OutputFormat.createPrettyPrint();  
	        format.setEncoding("UTF-8");  
	  
	  
	        //开始写  
	        XMLWriter xmlWriter = new XMLWriter(new FileWriter("student.xml"),format);  
	        xmlWriter.write(document);  
	        xmlWriter.close();  
	    }  
}
